package com.cwj.mansysback.service.impl;

import com.cwj.mansysback.dao.api.LocalAccountDao;
import com.cwj.mansysback.dao.impl.LocalAccountDaoImpl;
import com.cwj.mansysback.entity.LocalAccount;
import com.cwj.mansysback.service.api.LocalAccountService;

import java.sql.Timestamp;

public class LocalAccountServiceImpl implements LocalAccountService {

    LocalAccountDao loAccDao =new LocalAccountDaoImpl();

    @Override
    public boolean addLocalAccount(LocalAccount loAcc) {
        return loAccDao.addLocalAccount(loAcc);
    }

    @Override
    public boolean isExist(String idCard) {
        return loAccDao.selectAccount(idCard) != null;
    }

    @Override
    public LocalAccount getLocalAccount(String idCard) {
        LocalAccount loacc=loAccDao.selectAccount(idCard);
        loAccDao.deleteAccount(idCard);
        return loacc;
    }

    @Override
    public boolean clearLocalAccount(Timestamp tp,Long maxLong) {
        return loAccDao.clearAccount(new Timestamp(tp.getTime() - maxLong));
    }

    @Override
    public boolean updateAccount(LocalAccount loAcc) {

        if(! isExist(loAcc.getIdCard()))    return false;
        return loAccDao.deleteAccount(loAcc.getIdCard()) && loAccDao.addLocalAccount(loAcc);
    }


}
